package com.lisx.module_note.dialogfragment;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.ijianji.lsx_ui_lib.BaseDialogFragment;
import com.lisx.module_note.R;
import com.lisx.module_note.adapter.SelectAdapter;
import com.lisx.module_note.bean.SelectIconBean;

public class SelectDialogFragment extends BaseDialogFragment {

    int moodRes = 0;
    int weatherRes = 0;

    @Override
    public int getLayoutRes() {
        return R.layout.dialog_fragment_select;
    }

    @Override
    public void initView(Context context, View view, AttributeSet attributeSet) {
        RecyclerView moodRecyclerView = view.findViewById(R.id.moodRecyclerview);
        RecyclerView weatherRecyclerview = view.findViewById(R.id.weatherRecyclerview);

        moodRecyclerView.setLayoutManager(new GridLayoutManager(context, 6));
        SelectAdapter moodAdapter = new SelectAdapter(SelectIconBean.getMoodIconData());
        moodRecyclerView.setAdapter(moodAdapter);
        moodAdapter.setOnItemClickListener(new SelectAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int res) {
                moodRes = res;
            }
        });

        weatherRecyclerview.setLayoutManager(new GridLayoutManager(context, 6));
        SelectAdapter weatherAdapter = new SelectAdapter(SelectIconBean.getWeatherIconData());
        weatherRecyclerview.setAdapter(weatherAdapter);
        weatherAdapter.setOnItemClickListener(new SelectAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int res) {
                weatherRes = res;
            }
        });

        view.findViewById(R.id.tv_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

        view.findViewById(R.id.tv_qd).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.onSelectIcon(moodRes, weatherRes);
                }
                dismiss();
            }
        });
    }

    @Override
    public void initData(Context context) {

    }

    @Override
    public void initEvent(Context context) {

    }

    public interface OnSelectIconListener {
        void onSelectIcon(int moodRes, int weatherRes);
    }

    OnSelectIconListener listener;

    public void setOnSelectIconListener(OnSelectIconListener listener) {
        this.listener = listener;
    }
}
